package com.bocek.chakmapoint.controller;

import java.io.File;

import javax.swing.JFileChooser;
import javax.xml.parsers.ParserConfigurationException;

import com.bocek.chakmapoint.model.SlideList;

public class MainController {

	private static MainController instance = null;

	private SlideEditController slideEditController = SlideEditController
			.getInstance();
	private SlideSortController slideSortController = SlideSortController
			.getInstance();
	private SlideshowController slideshowController = SlideshowController
			.getInstance();

	String slideMode = "edit";

	public MainController() {
	}

	public static MainController getInstance() {
		if (instance == null) {
			instance = new MainController();
		}
		return instance;
	}

	public void presentSlideshow() {
		slideMode = "show";

		slideshowController.activate();
	}

	public void switchToEdit() {
		slideMode = "edit";

		slideEditController.activate();
	}

	public void switchToSort() {
		slideMode = "sort";

		slideSortController.activate();
	}

	public void viewHelpDocumentation() {
	}

	public void handleButtonEvent() {
	}

	public void saveButtonPressed() {
		JFileChooser fc = new JFileChooser();
		int result = fc.showSaveDialog(null);
		if (result == JFileChooser.APPROVE_OPTION) {
			File file = fc.getSelectedFile();
			try {
				SlideList.saveToXML(file.getPath());
			} catch (ParserConfigurationException e) {
				e.printStackTrace();
			}
		}
	}

	public void loadButtonPressed() {
		JFileChooser fc = new JFileChooser();
		int returnButton = fc.showOpenDialog(null);

		if (returnButton == JFileChooser.APPROVE_OPTION) {
			File file = fc.getSelectedFile();

			SlideList.setSlides(SlideList.loadFromXML(file.getPath()));
		}
	}
}
